<?php

namespace App\Presenters;

use \Nette\Application\UI\Form,
		\App\Components\Wizard,
		\App\Components\StepDependency;

/**
 * Homepage presenter.
 */
class HomepagePresenter extends BasePresenter {
	
	/**
	 * render result of test form
	 */
	public function renderResult(){
		$result = null;
		if(isset($_SESSION['result'])){
			$result = $_SESSION['result'];
			unset($_SESSION['result']);
		}
		$this->template->result = $result;
	}

	/**
	 * Prepare and create component Wizard
	 * 
	 * @return \App\Components\Wizard
	 */
	public function createComponentWizard() {
		
		// login form
		$loginForm = new Form();
		$loginForm->addText('login', 'Login name')
				->addRule(Form::FILLED, 'Login name must be filled');
		$loginForm->addPassword('password', 'Login password')
				->addRule(Form::FILLED, 'Missing password');
		$loginForm->addPassword('passwordAgain', 'Login password again')
				->addRule(Form::FILLED, 'Missing password again');
		
		// person form
		$personForm = new Form();
		$personForm->addText('personFirstname', 'Person first name')
				->addRule(Form::FILLED, 'Name must by filled');
		$personForm->addText('personMidlename', 'Person midle name');
		$personForm->addText('personLastName', 'Person last name')
				->addRule(Form::FILLED, 'Last name must by filled');
		$personForm->addText('personTitles', 'Person titles');
		
		// country form
		$countryArr = array(1=>'Czech republic', 2=>'Slovakia');
		$countryForm = new Form();
		$countryForm->addSelect('country', 'Country', $countryArr, 1);
		
		// contact form
		$contactForm = new Form();
		$contactForm->addText('email', 'Your email')
				->addRule(Form::FILLED, 'Email must be filled')
				->addRule(Form::EMAIL, 'This is not valid email address');
		$contactForm->addText('phone', 'Telephone')
				->addCondition(Form::FILLED)
				->addRule(Form::NUMERIC, 'Telephone must by number');
		
		// location form
		$locationForm = new Form();
		$locationForm->addText('city', 'City');
		$locationForm->addText('street', 'Street');
		$locationForm->addText('houseNumber', 'House number');
		$locationForm->addText('zip', 'ZIP');
		
		$wizard = new Wizard();
		
		// dependency array 1 + step 1
		$dependencyArrayStep1 = array(
				// kdyz je input login nastaven na jirka, ve druhem kroku nebudou polozky personFirstname a personMidlename
				new StepDependency('login', 'jirka', 'step_2', array('personFirstname', 'personMidlename')),
				// a v sestem kroku nebude input street
				new StepDependency('login', 'jirka', 'step_6', array('street')),
				// pokud je password nastaven na admin v sestem kroku nebude input city
				new StepDependency('password', 'admin', 'step_6', array('city')),
			);
		$wizard->addStep('step_1', 'Login credentials', 'Fill your login information', $loginForm, $dependencyArrayStep1);
		
		// step 3
		$wizard->addStep('step_2', 'Personal information', 'Fill your personal information', $personForm);
		
		// dependency + step 3
		// pokud je country nastaveno na 1 - tedy ceska republika, v patem kroku se neobjevi input phone
		$dependencyArrayStep3 = array(new StepDependency('country', 1, 'step_5', array('phone')));
		$wizard->addStep('step_3', 'Country', 'Select country', $countryForm, $dependencyArrayStep3);
		
		// step 4
		$wizard->addStep('step_4', 'Neco', 'Jenom ze to jde udelat i bez formulare, tzn info nejake jen tak');
		
		// step 5
		$wizard->addStep('step_5', 'Contact', 'Contact information', $contactForm);
		
		// step 6
		$wizard->addStep('step_6', 'location', 'Fill your location', $locationForm);
		
		return $wizard;
	}
}
